home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-18 | 5.6 KB | 193 lines | [TEXT/CCL2] |
- ;;;;ADLM.lisp
- ;;;;AfterDark LISP Module written in Macintosh Common LISP.
- ;;;;This is the (non-gratuitously) largest AfterDark Module you will ever see.
- ;;;;Special thanks to all the people I bugged with idiotic ToolBox questions.
-
- (defparameter *min-pts* 10 "Minimum number of points in a region.")
- (defparameter *rnd-pts* 10 "Maximum number of additional points in a region.")
- (defparameter *sleep-cnt* 1 "Seconds to leave a region inverted.")
-
- (defun select-window ()
- "Lets the user pick a window and returns it."
- (car (select-item-from-list (windows)))
- )
-
- (defun ADLM-black (&optional (port (wptr (select-window))))
- "port
- Does not-so-funky screen-saver things to port…paints all of port black."
- (with-port port
- (with-fore-color *black-color*
- (#_FillRgn (rref port :GrafPort.visrgn) *black-pattern*)
- ) )
- (let (start
- where
- )
- (rlet ((loc :long))
- (#_GetMouse loc)
- (setq start (%get-long loc))
- (setq where start)
- (do ()
- ((/= where start) (mouse-down-p))
- (#_GetMouse loc)
- (setq where (%get-long loc))
- ) ) )
- (quit)
- )
-
- (defun ADLM-random-regions (&optional (port (wptr (select-window))))
- "port
- Does funky screen-saver things to port.
- Specifically, it uses standard AI-vision edge-detection to find objects in
- the port, and then blacks-out/restores randomly selected objects.
- All right, so the seedFill and SeedCFill routines don't work.
- Go for random regions."
-
- (with-port port
- (let* ((rect (rref port :GrafPort.PortRect))
- (left (rref rect :rect.left))
- (top (rref rect :rect.top))
- (right (rref rect :rect.right))
- (bottom (rref rect :rect.bottom))
- (width (- right left))
- (height (- bottom top))
- (rgn (#_NewRgn))
- mouse-start
- start-h
- start-v
- h
- v
- )
- (unwind-protect
- (rlet ((loc :point))
- (#_GetMouse loc)
- (setq mouse-start (%get-long loc))
- (do* ((mouse-pos (%get-long loc) (%get-long loc)))
- ((or (/= mouse-pos mouse-start) (mouse-down-p)))
- (#_OpenRgn)
- (setq start-h (+ left (random width)))
- (setq start-v (+ top (random height)))
- (#_MoveTo start-h start-v)
- (unwind-protect
- (dotimes (i (+ *min-pts* (random *rnd-pts*)))
- (setq h (+ left (random width)))
- (setq v (+ top (random height)))
- (#_LineTo h v)
- )
- (#_LineTo start-h start-v)
- (#_CloseRgn rgn)
- (unwind-protect
- (progn
- (#_InvertRgn rgn)
- (sleep *sleep-cnt*)
- )
- (#_InvertRgn rgn)
- (#_GetMouse loc)
- ) ) ) )
- (#_DisposeRgn rgn)
- ) ) )
- (quit)
- )
-
- ;;;;An automatically closing about-win.
- (defclass about-win (color-dialog)
- ((time-up
- :documentation "Time it first showed up."
- :accessor time-up
- :initarg :time-up
- :initform (get-universal-time)
- :type 'fixnum
- )
- )
- (:default-initargs
- :window-type :double-edge-box
- :view-position :centered
- :color-p *color-available*
- ) )
-
- (defmethod window-null-event-handler ((view about-win))
- (when (> (- (get-universal-time) (time-up view)) 30)
- (return-from-modal-dialog nil)
- ) )
-
- (defmethod initialize-instance :after ((view about-win) &key)
- (apply #'remove-menu-items *apple-menu* (menu-items *apple-menu*))
- (add-menu-items *apple-menu*
- (make-instance 'menu-item
- :menu-item-title "About Me"
- :menu-item-action #'launch
- )
- (make-instance 'menu-item :menu-item-title "-")
- ) )
-
- (defmethod view-key-event-handler ((view about-win) char)
- (declare (ignore char))
- (return-from-modal-dialog nil)
- )
-
- ;;;;I can have as many functions as I want to shoot off at startup and
- ;;;;shutdown.
-
- (defun launch ()
- "This function will be called at launch time."
-
- (modal-dialog
- (make-instance 'about-win
- :view-size #@(400 150)
- :view-subviews
- (list
- (make-instance 'static-text-dialog-item
- :dialog-item-text "This is not quite done, but released."
- :view-position #@(20 20)
- :view-size #@(360 110)
- :view-font '("Helvetica" 40)
- :part-color-list
- (when *color-available*
- (list :text *red-color*)
- )
- )
- (make-instance 'button-dialog-item
- :dialog-item-text "Ok"
- :view-font '("Helvetica" 14 :bold)
- :view-position #@(300 125)
- :view-size #@(70 20)
- :default-button t
- :part-color-list
- (when *color-available*
- (list :text *red-color* :body *blue-color* :frame *green-color*)
- )
- :dialog-item-action
- #'(lambda (button)
- (declare (ignore button))
- (return-from-modal-dialog nil)
- )
- )
- ) ) ) )
-
- ;;;;full-screen
- (defclass full-screen (window)
- ()
- (:default-initargs
- :view-position #@(0 0)
- :view-size (make-point *screen-width* *screen-height*)
- :window-type :single-edge-box
- ) )
-
- (defmethod view-key-event-handler ((view full-screen) char)
- (declare (ignore char))
- (quit)
- )
-
- ;;;;screen-saver
-
- (defun screen-saver ()
- "I need hide-menubar and some other junk I left at home, 'natch."
- (let ((foo (shift-key-p)))
- (cond
- (foo (ADLM-black (wptr (make-instance 'full-screen))))
- ((null foo) (ADLM-random-regions (wptr (make-instance 'full-screen))))
- (t (quit))
- ) ) )
-
- (setq *restore-lisp-functions*
- (append *restore-lisp-functions* (list #'launch #'screen-saver))
- )